/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FramePrincipal.java
 *
 * Created on 24/07/2009, 23:05:51
 */
package br.di0.nyx;

import br.di0.nyx.cadastro.*;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;

/**
 *
 * @author di0
 */
public class FramePrincipal extends javax.swing.JFrame {

    /** Creates new form FramePrincipal
     * @param titulo O titulo a da Janela
     */
    public FramePrincipal(String titulo) {
        initComponents();
        this.setTitle(titulo);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        MenuBar = new javax.swing.JMenuBar();
        commerceMenu = new javax.swing.JMenu();
        entradasMenuItem = new javax.swing.JMenuItem();
        saidasMenuItem = new javax.swing.JMenuItem();
        estoqueMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        sairMenuItem = new javax.swing.JMenuItem();
        cadastroMenu = new javax.swing.JMenu();
        cadastroClienteMenuItem = new javax.swing.JMenuItem();
        cadastroFornecedorMenuItem = new javax.swing.JMenuItem();
        cadastroProdutoMenuItem = new javax.swing.JMenuItem();
        cadastroUsuarioMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(900, 700));

        desktopPane.setName("desktopPane"); // NOI18N

        commerceMenu.setMnemonic('M');
        commerceMenu.setText("Movimentação");

        entradasMenuItem.setMnemonic('C');
        entradasMenuItem.setText("Compra");
        entradasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                entradasMenuItemActionPerformed(evt);
            }
        });
        commerceMenu.add(entradasMenuItem);

        saidasMenuItem.setMnemonic('V');
        saidasMenuItem.setText("Venda");
        saidasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saidasMenuItemActionPerformed(evt);
            }
        });
        commerceMenu.add(saidasMenuItem);

        estoqueMenuItem.setMnemonic('T');
        estoqueMenuItem.setText("Estoque");
        estoqueMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                estoqueMenuItemActionPerformed(evt);
            }
        });
        commerceMenu.add(estoqueMenuItem);
        commerceMenu.add(jSeparator1);

        sairMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        sairMenuItem.setMnemonic('S');
        sairMenuItem.setText("Sair");
        sairMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairMenuItemActionPerformed(evt);
            }
        });
        commerceMenu.add(sairMenuItem);

        MenuBar.add(commerceMenu);

        cadastroMenu.setMnemonic('d');
        cadastroMenu.setText("Cadastro");

        cadastroClienteMenuItem.setMnemonic('C');
        cadastroClienteMenuItem.setText("Cliente");
        cadastroClienteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastroClienteMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(cadastroClienteMenuItem);

        cadastroFornecedorMenuItem.setMnemonic('F');
        cadastroFornecedorMenuItem.setText("Fornecedor");
        cadastroFornecedorMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastroFornecedorMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(cadastroFornecedorMenuItem);

        cadastroProdutoMenuItem.setMnemonic('P');
        cadastroProdutoMenuItem.setText("Produto");
        cadastroProdutoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastroProdutoMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(cadastroProdutoMenuItem);

        cadastroUsuarioMenuItem.setMnemonic('U');
        cadastroUsuarioMenuItem.setText("Usuário");
        cadastroUsuarioMenuItem.setEnabled(false);
        cadastroUsuarioMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastroUsuarioMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(cadastroUsuarioMenuItem);

        MenuBar.add(cadastroMenu);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cadastroClienteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastroClienteMenuItemActionPerformed
        CadastroInternalFrame cliente = new CadastroInternalFrame("Cadastro de Clientes",
                CadastroInternalFrame.CLIENTE);
        addInternalFrame(desktopPane, cliente, true, true);
}//GEN-LAST:event_cadastroClienteMenuItemActionPerformed

    private void cadastroFornecedorMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastroFornecedorMenuItemActionPerformed
        CadastroInternalFrame fornecedor = new CadastroInternalFrame("Cadastro de Fornecedores",
                CadastroInternalFrame.FORNECEDOR);
        addInternalFrame(desktopPane, fornecedor, true, true);
    }//GEN-LAST:event_cadastroFornecedorMenuItemActionPerformed

    private void cadastroProdutoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastroProdutoMenuItemActionPerformed
        CadastroProdutos produto = new CadastroProdutos("Cadastro de Produtos");
        addInternalFrame(desktopPane, produto, true, true);
    }//GEN-LAST:event_cadastroProdutoMenuItemActionPerformed

    private void entradasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_entradasMenuItemActionPerformed
        MovimentoInternalFrame compra =  new MovimentoInternalFrame("Compras", MovimentoInternalFrame.FORNECEDOR);
        addInternalFrame(desktopPane, compra, true, true);
    }//GEN-LAST:event_entradasMenuItemActionPerformed

    private void saidasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saidasMenuItemActionPerformed
        MovimentoInternalFrame venda =  new MovimentoInternalFrame("Vendas", MovimentoInternalFrame.CLIENTE);
        addInternalFrame(desktopPane, venda, true, true);
    }//GEN-LAST:event_saidasMenuItemActionPerformed

    private void estoqueMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_estoqueMenuItemActionPerformed
        //javax.swing.JOptionPane.showMessageDialog(null, "Implemente aqui");
         CadastroEstoque estoque =  new CadastroEstoque();
        addInternalFrame(desktopPane, estoque, true, true);
    }//GEN-LAST:event_estoqueMenuItemActionPerformed

    private void sairMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairMenuItemActionPerformed
        System.exit(0);
}//GEN-LAST:event_sairMenuItemActionPerformed

    private void cadastroUsuarioMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastroUsuarioMenuItemActionPerformed
        CadastroUsuario usuario = new CadastroUsuario("Cadastro de Usuários");
        addInternalFrame(desktopPane, usuario, true, true);
    }//GEN-LAST:event_cadastroUsuarioMenuItemActionPerformed

    /**
     * Adiciona um JInternalFrame em um JDesktopPane
     * @param desktop o JDesktopPane que receberá o internalFrame
     * @param internalFrame o JInternalFrame que será adicionado
     * @param selected determina se o JInternalFrame iniciará visível
     * @param selected tenta selecionar o JInternalFrame caso ele esteja visivel
     */
    private void addInternalFrame(JDesktopPane desktop, JInternalFrame internalFrame,
            boolean visible, boolean selected) {
        desktop.add(internalFrame);
        if (visible) {
            internalFrame.setVisible(visible);
            try {
                internalFrame.setSelected(selected);
            } catch (java.beans.PropertyVetoException e) {
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FramePrincipal("Nyx").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JMenuItem cadastroClienteMenuItem;
    private javax.swing.JMenuItem cadastroFornecedorMenuItem;
    private javax.swing.JMenu cadastroMenu;
    private javax.swing.JMenuItem cadastroProdutoMenuItem;
    private javax.swing.JMenuItem cadastroUsuarioMenuItem;
    private javax.swing.JMenu commerceMenu;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem entradasMenuItem;
    private javax.swing.JMenuItem estoqueMenuItem;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenuItem saidasMenuItem;
    private javax.swing.JMenuItem sairMenuItem;
    // End of variables declaration//GEN-END:variables
}
